<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=utf-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>资源库单位注销</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="${pageContext.request.contextPath }/scripts/boot.js" type="text/javascript"></script>
<style type="text/css">
html,body {
	font-size: 12px;
	padding: 0;
	margin: 0;
	border: 0;
	height: 100%;
	overflow: hidden;
}
</style>
</head>
<body>
	<fieldset style="border:solid 1px #aaa;padding:3px;">
	<legend>业务数据信息</legend>
	<form id="form1" method="post">						
	<div style="padding-left:11px;padding-bottom:5px; ">
	<table style="table-layout:fixed;">
	<tr>				    
		<td style="width:180px;text-align:right;"><span style="color:red;">*</span>劳动保障证号：</td>
		<td style="width:180px;"><input name="aab001" id="id" style="width:84%" class="mini-textbox" onenter="checkdata"
									required="true"	 maxlength="8" emptyText="请输入8位劳动保障证号"/></td>
		<td style="width:180px;text-align:right;">单位名称：</td>
		<td style="width:180px;"><input name="aab004" inputStyle="background:rgb(241,241,243)" allowInput="false" 
										readonly="true" style="width:90%" id="unit_name" class="mini-textbox "
										maxlength="25" /></td>
		<td style="width:180px;text-align:right;">单位性质：</td>
		<td style="width:180px;"><input id="aab019" name="aab019" class="mini-combobox " style="width:84%;" 
										inputStyle="background:rgb(241,241,243)" allowInput="false" readonly="true"					
										valueField="aaa102" textField="aaa103" 
										url="${pageContext.request.contextPath }/unit.do?method=getselect&lx=AAB019"/></td>
	</tr>
	<tr>						
		<td style="width:180px;text-align:right;">统一社会信用代码：</td>
		<td style="width:180px;"><input name="aab998" inputStyle="background:rgb(241,241,243)" allowInput="false"
										readonly="true" style="width:84%" id="credit_id" class="mini-textbox" maxlength="18"/></td>
		<td style="width:180px;text-align:right;">组织机构代码：</td>
		<td style="width:180px;"><input name="aab003" style="width:90%" id="organization_id" class="mini-textbox" 
										inputStyle="background:rgb(241,241,243)" allowInput="false" readonly="true"
										maxlength="10" /></td>
		<td style="width:180px;text-align:right;">地税登记证号：</td>
		<td style="width:180px;"><input name="aab030" style="width:84%" class="mini-textbox" maxlength="40"
										inputStyle="background:rgb(241,241,243)" allowInput="false" readonly="true" /></td>
	</tr>
	<tr>
		<td style="width:180px;text-align:right;">联系人：</td>
		<td style="width:180px;"><input name="aae004" style="width:84%" class="mini-textbox" 
										inputStyle="background:rgb(241,241,243)" allowInput="false" readonly="true" 
										maxlength="15"  /></td>
		<td style="width:180px;text-align:right;">联系电话：</td>
		<td style="width:180px;"><input name="aae005" style="width:90%" class="mini-textbox" 
										inputStyle="background:rgb(241,241,243)" allowInput="false" readonly="true"
										vtype="int" maxlength="11"  /></td>
		<td style="width:180px;text-align:right;">法定代表人姓名：</td>
		<td style="width:180px;"><input name="aab013" style="width:84%" class="mini-textbox"
										inputStyle="background:rgb(241,241,243)" allowInput="false" readonly="true"
										maxlength="15"  /></td>
	</tr>
	<tr>
		<td style="width:180px;text-align:right;white-space:nowrap;">法定代表人证件类型：</td>
		<td style="width:180px;"><input name="aae018" inputStyle="background:rgb(241,241,243)" allowInput="false" 
										readonly="true" valueField="aaa102" textField="aaa103" class="mini-combobox" 
										url="${pageContext.request.contextPath }/unit.do?method=getselect&lx=AAC058"
										style="width:84%" id="documenttype"/></td>
		<td style="width:180px;text-align:right;">法定代表人证件号码：</td>
		<td style="width:180px;"><input name="aab014" style="width:90%" class="mini-textbox" maxlength="25"
										inputStyle="background:rgb(241,241,243)" allowInput="false" readonly="true"/></td>
		<td style="width:180px;text-align:right;white-space:nowrap;">法定代表人联系电话：</td>
		<td style="width:180px;"><input name="aab015" inputStyle="background:rgb(241,241,243)" allowInput="false"
										readonly="true" style="width:84%" class="mini-textbox" vtype="int" maxlength="11"/></td>
	</tr>
	<tr>																						
		<td style="width:180px;text-align:right;"><span style="color:red;">*</span>注销原因：</td>
		<td style="width:180px;"><input name="aab620" valueField="aaa102" textField="aaa103" 
										url="${pageContext.request.contextPath }/unit.do?method=getselect1&lx=AAB620"
										style="width:84%" class="mini-combobox" required="true"
										maxlength="15" emptyText="请选择注销原因" /></td>
		<td style="width:180px;text-align:right;"><span style="color:red;">*</span>单位注销日期：</td>
		<td style="width:180px;"><input name="aab523" style="width:90%" class="mini-datepicker" required="true"
										maxlength="20" emptyText="请输入注销日期" /></td>	
	</tr>										
	</table>
	</div>
	<div style="text-align:center;padding:10px;">
		<a class="mini-button" name="onok" id="onok" onclick="cancle" enabled="false" iconCls="icon-ok" style="width:60px;margin-right:20px;">确定</a> 
		<a class="mini-button" iconCls="icon-remove" onclick="onReset" style="width:60px;">重置</a>
	</div>
	</form>
	</fieldset>
<script type="text/javascript">
	function ondwChanged(){
	    var credit_id = mini.get("#credit_id");
   	 	var organization_id = mini.get("#organization_id");
    	var landtax = mini.getbyName("aab030");
		var f=mini.get("#aab019").getValue();
		if(f=="10"){
		    landtax.setValue("");			    	    
		    credit_id.setEmptyText("统一社会信用代码(18位)");
		    credit_id.setAllowInput(true);
		    credit_id.setRequired(false);
			organization_id.setAllowInput(true);
			landtax.setAllowInput(true);
			landtax.setEmptyText("请输入地税登记证号");				
		}
		//机关、事业单位
		if(f=="30"||f=="50"){
		    landtax.setValue("");
		    credit_id.setValue("");
		    credit_id.setEmptyText("");
			credit_id.setAllowInput(false);		    
			organization_id.setAllowInput(true);
			organization_id.setRequired(true);
			landtax.setAllowInput(false);
			landtax.setEmptyText("");
		}
		//社会团体
		if(f=="70"){
		    credit_id.setValue("");	
		    credit_id.setEmptyText("");
	        credit_id.setAllowInput(false);
			organization_id.setAllowInput(true);
			organization_id.setRequired(true);
			landtax.setAllowInput(true);
			landtax.setEmptyText("请输入地税登记证号");
		}
		if(f=="81"){
			credit_id.setValue("");	
			landtax.setValue("");
			credit_id.setEmptyText("统一社会信用代码(18位)");
			credit_id.setAllowInput(true);
			credit_id.setRequired(false);
			organization_id.setAllowInput(true);
			organization_id.setRequired(false);
			landtax.setAllowInput(true);
			landtax.setEmptyText("请输入地税登记证号");
		}
	}
        var judge=true;
        var judge2=true;
        mini.parse();
        var aab131 = mini.getbyName("aab998").getValue();
        var aab003 = mini.getbyName("aab003").getValue();
        if(aab131==" "){mini.getbyName("aab998").setValue("");}
        if(aab003==" "){mini.getbyName("aab003").setValue("");}
        var form = new mini.Form("form1");
    function SaveData() {
    	var o = form.getData();                   
        form.validate();
        if (form.isValid() == false) return;
        var json = mini.encode([o]);
        $.ajax({
            url: "/zyk/unit.do?method=saveunit",
			type: 'post',
            data: { data: json},
            cache: false,
            success: function (text) {
            	mini.alert("注销成功!");
                form.clear();
                mini.get("onok").setEnabled(false);
             //   mini.get("onok").setEnabled("false");
            },
            error: function (jqXHR, textStatus, errorThrown) {
                mini.alert(jqXHR.responseText);
                CloseWindow();
            }
        });
    }
    function checkdata() {
    	mini.getbyName("aab001").setEnabled(false);
    	var aab001 = mini.getbyName("aab001").getValue().trim();
    	if (aab001.length<8 && aab001.length>=0) {
			mini.alert("劳动保障证号必须为8位数字");
			mini.getbyName("aab001").setValue("");
			mini.getbyName("aab001").setEnabled(true);
			return;
			}
        $.ajax({               
        	url: "/zyk/unit.do?method=getunitdata1",
            cache: false,
            data:{id:aab001},
            success: function (text) {                 
                var o = mini.decode(text);   
                if(o==null){
                	mini.alert("无该劳动保障证号的单位！");
                	mini.getbyName("aab001").setValue("");
                	mini.getbyName("aab001").setEnabled(true);
                	return ;
                } else if (o.aab620!='0'&&o.aab620!='') {
                	mini.alert("该单位已注销！");
                	mini.getbyName("aab001").setValue("");
                	mini.getbyName("aab001").setEnabled(true);
                	form.clear();
                	return ;
                } else {
                form.setData(o);
                mini.getbyName("aab620").setValue("");
                mini.get("onok").setEnabled("true");
                form.setChanged(false);
            }
            }
        });
		
        
    }
    function GetData() {
        var o = form.getData();
        return o;
    }
    function CloseWindow(action) {            
        if (action == "close" && form.isChanged()) {
            if (confirm("数据被修改了，是否先保存？")) {
                return false;
            }
        }
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        	else window.close();            
    } 
    function onOk(e) {
        var credit_id = mini.get("#credit_id").getValue();
		var organization_id = mini.get("#organization_id").getValue();
		var f=mini.get("#aab019").getValue();
		if(f=='10'&&credit_id==''&&organization_id==''){
		 	mini.alert("统一社会信用代码、组织机构代码不能同时为空");
		 	judge2=false;
		}
		if(f=='10'&&credit_id!=''&&organization_id!=''){
			mini.alert("统一社会信用代码、组织机构代码不能同时采集");
			judge2=false;
	 	}
        checkName();
        var aab131 = mini.getbyName("aab998").getValue();
        if(aab131.length>0){
        	CheckNumber(e);
         }
         if(judge&judge2){       
         	SaveData();
         }
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }
        function onNumber(e){
			var zjlx=mini.get("#documenttype").getValue();
			if(zjlx == '1'){
				if(e.isValid){
					if(isNumber(e.value) == false){
						e.errorText = "身份证输入不合法";
						e.isValid = false;
					}
				}
			}
		}	
	function isNumber(v){
        var tel = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i;
        var flag = true;
        if(!tel.test(v)){
            flag = false;
        }else{
            var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
            var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
            var nTemp = 0, i;
            var temp = v.substring(0,17);
            for (i = 0; i < temp.length; i++) {
                 nTemp += temp.substr(i, 1) * arrInt[i];
                }
                temp += arrCh[nTemp % 11];
            if(temp != v) {
               flag = false;
            }
        }
        return flag;
    }
    function isOrganization(v){
        var re = new RegExp("^([0-9A-Z]){7}-[0-9|X]$");
        if (re.test(v)) return true;
        return false;
    }
	//检测组织ID是否重复
    function CheckOrganizationId(v){
        if(v.isValid){
			if(isOrganization(v.value) == false&&v.value!=''){
				v.errorText = "组织机构输入不合法";
				v.isValid = false;
			//mini.alert(e.errorText);
			}
		}
		var id = mini.get("#organization_id").getValue().trim();
        var aab001=mini.get("#id").getValue().trim();
	 	$.ajax({
        	url: "/zyk/unit.do?method=getunitorganizationid",
            dataType : 'JSON',
			data : {id:id,aab001:aab001},
            success: function(result) {
			//已经存在组织机构代码字提示用户
			if(result != null){
				mini.get("#organization_id").setValue();  
				mini.alert("组织机构代码重复，请重新输入");
				judge=false;
			}else{
				judge=true;
			}
						}	
        });
    }
	//发ajax请求到后台判断用户名是否重复
     function checkName(){
     var name = mini.get("#unit_name").getValue();
     var id = mini.get("#id").getValue();
	 $.ajax({
    	url: "/zyk/unit.do?method=getunitname",
        async:false,
        dataType : 'JSON',
		data : {name:name},
		success: function(result) {
		//已经存在该名字提示用户
		if(result != null){
			if(id==result.aab001){judge=true;} else{
				mini.alert("该单位已注册，请核实");
				judge=false;
			}
		}else{
			judge=true;
			}
		}	
      });
      }
    function CheckNumber(e){
	var AAB998 = mini.getbyName("aab998").getValue();
	if(AAB998.length<18&AAB998.length>=1){
	mini.alert("信用编码必须为18位");
	 // e.errorText = "信用编码必须为18位";
	 // e.isValid = false;
	  judge=false;
	} else {
		judge=true;
	}
   }
   function onReset(e) {
				form.clear();
				mini.get("onok").setEnabled(false);
				mini.getbyName("aab001").setEnabled(true);
			}
	function onDrawDate(e) {
		var date = e.date;
		var d = new Date();
		if (date.getTime() >= d.getTime()) {
		    e.allowSelect = false;
		}
	}
	 function cancle() {
	    	var o = form.getData();                   
	        form.validate();
	        if (form.isValid() == false) return;
	        var json = mini.encode([o]);
	        $.ajax({
	            url: "/zyk/unit.do?method=cancel",
				type: 'post',
	            data: { data: json},
	            cache: false,
	            success: function (text) {
	            	if(text == "0")
	            	{
	            		mini.alert("注销成功!");
	            		mini.getbyName("aab001").setEnabled(true);
	            	}
	            	else
	            	{
	            		mini.alert(text);
	            		return ;
	            	}
	      
	            	
	                form.reset();
	                mini.get("onok").setEnabled(false);
	             //   mini.get("onok").setEnabled("false");
	                CloseWindow("save");
	            },
	            error: function (jqXHR, textStatus, errorThrown) {
	                mini.alert(jqXHR.responseText);
	                CloseWindow();
	            }
	        });
	    }
	
    </script>
</body>
</html>
